package com.lanou.zhihu.service.impl;

import com.lanou.zhihu.entity.CommentGood;
import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.mapper.CommentGoodMapper;
import com.lanou.zhihu.service.CommentGoodSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by QuChao on 2018/10/31.
 */
@Service
public class CommentGoodSeviceImpl implements CommentGoodSevice {
    @Autowired
    private CommentGoodMapper commentGoodMapper;

    @Override
    public boolean findByUidCid(User user, Integer cid) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", user.getId());
        map.put("cid", cid);
        CommentGood commentGood = commentGoodMapper.findByUidCid(map);
        if (commentGood != null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Integer goodCountByCid(Integer cid) {
        Integer result = commentGoodMapper.goodCountByCid(cid);
        return result;
    }

    @Override
    public boolean good(User user, Integer cid) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", user.getId());
        map.put("cid", cid);
        Integer reslut = commentGoodMapper.insert(map);
        if (reslut == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean cancelGood(User user, Integer cid) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", user.getId());
        map.put("cid", cid);
        Integer result = commentGoodMapper.delete(map);
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }
}
